package com.daigou.dto;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class OrderQuery extends Query{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String status = "678";
	
	private String payStatus = "123";
	
	private List<Integer> payStatusList;
	
	private String timeType = "1";
	
	private Date filterTime = null;
	
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getPayStatus() {
		return payStatus;
	}

	public void setPayStatus(String payStatus) {
		this.payStatus = payStatus;
	}

	public List<Integer> getPayStatusList() {
		return payStatusList;
	}

	public void setPayStatusList(List<Integer> payStatusList) {
		this.payStatusList = payStatusList;
	}

	public String getTimeType() {
		return timeType;
	}

	public void setTimeType(String timeType) {
		this.timeType = timeType;
	}

	public Date getFilterTime() {
		return filterTime;
	}

	public void setFilterTime(Date filterTime) {
		this.filterTime = filterTime;
	}

	public void builderTime(){
		Date now = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(now);
		calendar.set(Calendar.HOUR_OF_DAY, 0);  
        calendar.set(Calendar.SECOND, 0);  
        calendar.set(Calendar.MINUTE, 0);  
        calendar.set(Calendar.MILLISECOND, 0);
        //本周
		if("week".equals(timeType)){
			int d = 0;
	        if (calendar.get(Calendar.DAY_OF_WEEK) == 1) {
	            d = -6;
	        } else {
	            d = 2 - calendar.get(Calendar.DAY_OF_WEEK);
	        }
	        calendar.add(Calendar.DAY_OF_WEEK, d);
			this.filterTime = calendar.getTime();
		}
		//本月
		else if("month".equals(timeType)){
			calendar.add(Calendar.MONTH, 0);
			calendar.set(Calendar.DAY_OF_MONTH,1);//设置为1号
			this.filterTime = calendar.getTime();
		}
		//本季度
		else if("season".equals(timeType)){
			calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONDAY), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);  
			calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.YEAR));
			this.filterTime = calendar.getTime();
		}
		//本半年
		else if("half".equals(timeType)){
			int currentMonth = calendar.get(Calendar.MONTH) + 1;
	        try {
	        	if (currentMonth >= 1 && currentMonth <= 6){
	        		calendar.set(Calendar.MONTH, 0);
	            }else if (currentMonth >= 7 && currentMonth <= 12){
	            	calendar.set(Calendar.MONTH, 6);
	            }
	        	calendar.set(Calendar.DATE, 1);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
			this.filterTime = calendar.getTime();
		}
		//今年
		else if("year".equals(timeType)){
			calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONDAY), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);  
			calendar.set(Calendar.DAY_OF_YEAR, calendar.getActualMinimum(Calendar.YEAR));
			this.filterTime = calendar.getTime();
		}
		//近一个月
		else if("1".equals(timeType)){
			calendar.add(Calendar.MONTH, -1);
			this.filterTime = calendar.getTime();
		}
		//近3个月
		else if("3".equals(timeType)){
			calendar.add(Calendar.MONTH, -3);
			this.filterTime = calendar.getTime();
		}
		else{
			this.filterTime = null;
		}
	}
	
	
	public static void main(String [] args){
		OrderQuery OrderQuery = new OrderQuery();
		OrderQuery.setTimeType("week");
		OrderQuery.builderTime();
		System.out.println(OrderQuery.getFilterTime());
		OrderQuery.setTimeType("month");
		OrderQuery.builderTime();
		System.out.println(OrderQuery.getFilterTime());
		OrderQuery.setTimeType("season");
		OrderQuery.builderTime();
		System.out.println(OrderQuery.getFilterTime());
		OrderQuery.setTimeType("half");
		OrderQuery.builderTime();
		System.out.println(OrderQuery.getFilterTime());
		OrderQuery.setTimeType("year");
		OrderQuery.builderTime();
		System.out.println(OrderQuery.getFilterTime());
		
		OrderQuery.setTimeType("1");
		OrderQuery.builderTime();
		System.out.println(OrderQuery.getFilterTime());
		
		OrderQuery.setTimeType("2");
		OrderQuery.builderTime();
		System.out.println(OrderQuery.getFilterTime());
		
	}
}
